define(function(require, exports, module){

	var popup = {

		init :function(opt){
			var html=boxHtml = '';
			this.dom = opt.dom;
			this.li = opt.li;
			this.type = opt.type;
			this.songid = opt.songid;
			this.tinguid = opt.tinguid;

			this.returnHtml();

			setTimeout(function(){
				$('.popup').addClass('show');
			},10);

			this.bindEvt();

			
		},

		returnHtml:function(){
			var tthis = this,type = this.type,html='',boxHtml;

			if(type == 'shareweb'){
				html = '<div class="shareweb">' +
							'<ul>' +
								'<li>' + 
									'<div class="bshare-custom">' + 
										'<a title="分享到QQ空间" class="bshare-qzone">QQ空间</a>' + 
									'</div>' + 
								'</li>' +
								'<li>' + 
									'<div class="bshare-custom">' + 
										'<a title="分享到新浪微博" class="bshare-sinaminiblog">新浪微博</a>' + 
									'</div>' + 
								'</li>' +
								'<li>' + 
									'<div class="bshare-custom">' + 
										'<a title="分享到微信" class="bshare-weixin">微信</a>' + 
									'</div>' + 
								'</li>' +
								'<li>' + 
									'<div class="bshare-custom">' + 
										'<a title="分享到Twitter" class="bshare-twitter">Twitter</a>' + 
									'</div>' + 
								'</li>' +
								'<li>' + 
									'<div class="bshare-custom">' + 
										'<a title="分享到Facebook" class="bshare-facebook">Facebook</a>' + 
									'</div>' + 
								'</li>' +
							'</ul>' +
						'</div>';
			}

			if(type == 'more'){
				var name,liObj = {
					singer :    '<li class="singer">查看歌手</li>',
					recommended : '<li class="recommended">相似歌曲</li>',
				};
				$.each(this.li,function(i){
					if(tthis.li[i] == 'all'){
						for(i in liObj){
							html += liObj[i];
						};
						return false;
					}
					name = tthis.li[i];
					html += liObj[name];
				});
				html =  '<div class="list_ul">' +
					 		'<ul>' + html + '</ul>' +
						'</div>';
			}

			html = '<div class="popup_shadow"></div><div class="popup">'+html+'</div>';
			
			// if(type == 'songList'){
			// 	html = '<div class="popup_shadow"></div>';
			// 	this.dom.addClass('show');
			// 	return;
			// }
			$('body').append(html);
		},

		show :function(opt){
			$('.popup').remove();
			this.init(opt);
		},

		close:function(){
			var tthis=this,dom = $('.popup');
			dom.removeClass('show');
			$('.popup_shadow').remove();
			setTimeout(function(){
				$('.popup').remove();
			},200)
		},
		bindEvt :function(){
			var tthis=this,dom = $('.popup'),type=this.type;

			$('.popup_shadow').on('tap',function(){
				tthis.close();
			});

			if(type == 'more'){

				dom.find('li').on('tap',function(){
					tthis.close();
				})

				dom.find('.recommended').on('tap',function(){
					// console.log(tthis.songid)
					window.location.href = '#recommended?songid='+tthis.songid;
				});
				dom.find('.singer').on('tap',function(){
					// console.log(tthis.songid)
					window.location.href = '#singerSongList?tinguid='+tthis.tinguid;
				});

			}

			if(type == 'shareweb'){
				
				dom.find('li').on('tap',function(){
					tthis.close();
				})

				dom.find('.close').on('tap',function(){
					tthis.cDom.hide();
					dom.removeClass('show');
					$('.popup,.popup_shadow').remove();
				});
			}
		},
	}

	module.exports = popup;
});